package com.hlw.springboot.mapper;

import com.hlw.springboot.entity.SysPermission;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface SysPermissionMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(SysPermission record);

    int insertSelective(SysPermission record);

    SysPermission selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(SysPermission record);

    int updateByPrimaryKey(SysPermission record);

    //根据角色ID查询角色对应的权限信息
    List<SysPermission> findPermissionByRoleId(@Param("roleId") Integer roleId);

    @Select("select distinct p.* from sys_permission p inner join sys_role_permission rp on p.id = rp.pid inner join sys_user_role ru on ru.rid = rp.rid where ru.uid = #{userId} order by p.order")
    List<SysPermission> listByUserId(int userId);

    @Select("select * from sys_permission where delflag = 0")
    List<SysPermission> selectAll();

    //layui table表格中行列进行编辑修改
    int updateById(@Param("params") Map<String, Object> params);

    //根据角色id删除对应权限
    @Delete("delete from sys_role_permission where rid = #{id}")
    int deletePerByrid(int id);
    //加权限
    @Insert(" insert into sys_role_permission(rid,pid)values(#{rid},#{pid})")
    Long inserPerByRid(@Param("rid")int rid,@Param("pid")int pid);


}